package com.wondersgroup.fjzlpt.yyzyzx.controller.rest.yyzygl;

import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.web.utils.RequestUtils;
import com.wondersgroup.fjzlpt.yyzyzx.beans.req.yyzygl.hygzgl.GljgRowReq;
import com.wondersgroup.fjzlpt.yyzyzx.beans.req.yyzygl.hygzgl.HygzDeleteReq;
import com.wondersgroup.fjzlpt.yyzyzx.beans.req.yyzygl.hygzgl.HygzQueryGljgReq;
import com.wondersgroup.fjzlpt.yyzyzx.beans.req.yyzygl.hygzgl.HygzQueryPageReq;
import com.wondersgroup.fjzlpt.yyzyzx.beans.req.yyzygl.hygzgl.HygzSaveGljgReq;
import com.wondersgroup.fjzlpt.yyzyzx.beans.req.yyzygl.hygzgl.HygzSaveReq;
import com.wondersgroup.fjzlpt.yyzyzx.beans.resp.BaseRespBean;
import com.wondersgroup.fjzlpt.yyzyzx.beans.resp.yyzygl.hygzgl.HygzQueryGljgResp;
import com.wondersgroup.fjzlpt.yyzyzx.beans.resp.yyzygl.hygzgl.HygzQueryPageResp;
import com.wondersgroup.fjzlpt.yyzyzx.service.inter.yyzygl.HygzglService;
import com.wondersgroup.fjzlpt.yyzyzx.util.ControllerUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Map;

/**
 * 号源规则管理
 * <p>
 * <p>
 * Created by sanma on 2017/8/2.
 */
@RestController
@RequestMapping("/hygzgl")
@Api(value = "号源规则管理接口" , tags = {"号源规则管理接口"} , description = "号源规则，关联机构增删改查操作")
public class HygzglRestController {
	
	@Autowired
	private HygzglService hygzglService;
	
	/**
	 * 保存/修改  号源规则
	 * @param request
	 * @return
	 */
	@ApiOperation(value = "号源规则保存" , notes = "新增与修改号源规则" ,response =  BaseRespBean.class)
	@RequestMapping(value = "save" , method = RequestMethod.POST)
	public JSONObject save(HttpServletRequest request , HygzSaveReq requestParams ){
		Map map = RequestUtils.GetParameterMap(request);
		return hygzglService.save(map);
	}
	
	/**
	 * 分页查询号源规则
	 * @param request
	 * @return
	 */
	@ApiOperation(value = "号源规则信息查询" , notes = "根据条件分页查询号源规则" ,response = HygzQueryPageResp.class)
	@RequestMapping(value = "queryPage" , method = RequestMethod.POST)
	public JSONObject queryPage(HttpServletRequest request , HygzQueryPageReq requestParams ){
		Map map = RequestUtils.GetParameterMap(request);
		ControllerUtils.setQueryParams(map,request);
		//JSONObject requestData = com.wondergroup.fjzlpt.tyzyzx.util.RequestUtils.getRequestData(request);
		//if(!requestData.getBoolean("isManager")){
		//	map.put("PTJGID" , requestData.get("PTJGID"));
		//}else{
		//	String xzqhdm = QuickPrincipalUtils.getXzqhdm(request);
		//	map.put("XZQHDM" , xzqhdm);
		//}
		return hygzglService.queryPage(map);
	}
	
	/**
	 * 删除号源规则
	 * @param request
	 * @return
	 */
	@ApiOperation(value = "删除号源规则" , notes = "根据ID删除号源规则" , response = BaseRespBean.class)
	@RequestMapping(value = "delete" , method = RequestMethod.POST)
	public JSONObject delete(HttpServletRequest request , HygzDeleteReq requestParams){
		Map map = RequestUtils.GetParameterMap(request);
		return hygzglService.delete(map);
	}
	
	/**
	 * 保存 号源规则的关联机构
	 * @param request
	 * @return
	 */
	@ApiOperation(value = "保存号源规则关联机构" , notes = "为该号源规则添加关联机构" , response = BaseRespBean.class)
	@RequestMapping(value = "saveGljg" , method = RequestMethod.POST )
	public JSONObject saveGljg(HttpServletRequest request  , HygzSaveGljgReq requestParams ,@RequestBody @ApiParam(value = "关联机构") ArrayList<GljgRowReq> list){
		Map map = RequestUtils.GetParameterMap(request);
		return hygzglService.saveGljg(map);
	}
	
	/**
	 * 查询 号源规则所有的关联机构
	 * @param request
	 * @return
	 */
	@ApiOperation(value = "号源规则关联机构" , notes = "根据号源规则查询关联机构" , response =  HygzQueryGljgResp.class)
	@RequestMapping(value = "queryGljg" , method = RequestMethod.POST)
	public JSONObject queryGljg(HttpServletRequest request , HygzQueryGljgReq gzbh ){
		Map map = RequestUtils.GetParameterMap(request);
		return hygzglService.queryGljg(map);
	}
	
}
